﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Economo.UI.Views;
using Economo.UI.Presenters;

namespace Economo.WinClient.Controls
{
    public partial class ManageBankAccounts : ManageEntities, IManageBankAccountsView 
    {
        public ManageBankAccounts()
        {
            InitializeComponent();
            _presenter = new ManageBankAccountsPresenter(this);
        }

        public override object GetEntityIdFromGridRow(int rowIndex)
        {
            try
            {
                ManageBankAccountsPresenter.BankAccountKey key = new ManageBankAccountsPresenter.BankAccountKey();
                key.AccountId = GetCellValueFromGridRow<Int16>(rowIndex, "Id");
                key.BankId = GetCellValueFromGridRow<Byte>(rowIndex, "BankId");
                return key;
            }
            catch
            {
                return null;
            }
        }
        #region View

        public byte? SelectedBankId
        {
            get
            {
                if (cmbBanks.SelectedIndex >= 0)
                    return (Byte)cmbBanks.SelectedValue;
                else
                    return null;
            }
            set
            {
                cmbBanks.SelectedValue = value;
            }
        }

        public IList Banks
        {
            get
            {
                return (IList)cmbBanks.DataSource;
            }
            set
            {                
                cmbBanks.DataSource = value;
                cmbBanks.Items.Add("All");
                cmbBanks.DisplayMember = "Description";
                cmbBanks.ValueMember = "Id";
            }
        }
        #endregion

        private void cmbBanks_SelectedIndexChanged(object sender, EventArgs e)
        {
            _presenter.FillData();
        }
    }
}
